// 2025/3/2
// https://leetcode.cn/problems/longest-substring-without-repeating-characters/description/?envType=study-plan-v2&envId=top-100-liked
// 无重复字符的最长字串

class Solution {
    public:
        int lengthOfLongestSubstring(string s) {
            int left = 0, right = 0, n = s.size();
            int count = 0, ans = 0;
            unordered_set<char> hash;
            while(right < n)
            {
                if(hash.count(s[right]))
                {
                    while(s[left] != s[right])
                    {
                        hash.erase(s[left++]);
                        count--;
                    }
                    left++;
                    right++;
                }
                else
                {
                    hash.emplace(s[right++]);
                    count++;
                    ans = max(ans, count);
                }
            }
            return ans;
        }
    };